package com.ray.friendslist.adaptor;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ray.friendslist.R;
import com.ray.friendslist.content.contract.FriendsContract;
import com.ray.friendslist.images.ImageLoader;

public class FriendsCursorAdapter extends CursorAdapter {

	public FriendsCursorAdapter(Context context, Cursor c) {
		super(context, c, true);
	}

	private ImageView mImageView1;

	@Override
	public void bindView(View view, Context ctx, Cursor cursor) {
		mImageView1 = (ImageView) view.findViewById(R.id.adapterIV);
		TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
		textView1
				.setText(cursor.getString(cursor
						.getColumnIndex(FriendsContract.FriendsColumns.VK_FRIEND_NAME)));
		ImageLoader
				.getInstance()
				.bind(this,
						mImageView1,
						cursor.getString(cursor
								.getColumnIndex(FriendsContract.FriendsColumns.VK_FRIEND_PHOTO_URL)));
	}

	@Override
	public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = View.inflate(arg0, R.layout.adapter_friends, null);
		return view;
	}
}
